﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeiXinPF.Common;
using WeiXinPF.Modules.Core.Admin.Application.Services;
using WeiXinPF.Templates;

namespace WeiXinPF.Web.modules.cdrt.smart
{
    /// <summary>
    /// 市民建言
    /// </summary>
    public partial class citizen_advice : TBasePage
    {
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!string.IsNullOrEmpty(errInitTemplates))
            {
                Response.Write(errInitTemplates);
                return;
            }

            var widInt = MyCommFun.RequestWid();
            if (wid <= 0)
            {
                errInitTemplates = Constants.MessageNoTempate;
                Response.Write(errInitTemplates);
                Response.End();
                return;
            }

            //重复代码，需要提取公用类及方法
            var requestOpenId = MyCommFun.RequestOpenid();
            if (MyCommFun.IsEmptyOpenId(requestOpenId))
            {
#if DEBUG
                requestOpenId = ConfigurationHelper.GetDebugOpenId();
#else
                var thisUrl = MyCommFun.getWebSite() + "/modules/cdrt/smart/citizen_advice.aspx?wid=" + widInt;
                var bll = new BLL.wx_userweixin();
                var uWeiXinModel = bll.GetModel(widInt);
                base.OAuth2BaseProc(uWeiXinModel, "citizen_advice", thisUrl);
#endif
            }

            string voteId = string.Empty;
            IVoteService service = new VoteService();
            var vote = service.GetDisplayVote(wid);
            voteId = vote == null ? "0" : vote.id.ToString();

            tPath = MyCommFun.GetRootPath() + "/modules/cdrt/smart/templates/citizen_advice.html";
            TemplateMgr template = new TemplateMgr(tPath, wid);
            template.tType = TemplateType.CitizenAdvice;
            template.ExtraValue = voteId;
            template.openid = requestOpenId;
            template.OutPutHtml(templateIndexFileName, wid);
        }
    }
}